import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:school_safe_teacher/resourse/app_colors.dart';
import 'package:school_safe_teacher/widget/my_widget.dart';
import 'package:school_safe_teacher/widget/no_message_widget.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(homeWorkListState state, Dispatch dispatch, ViewService viewService) {
  return body(
    child: Container(
      color: AppColors.MainBackColor,
      child: Column(
        children: [
          Container(
            child: myBar(context: viewService.context, title: "作业记录"),
            color: Colors.white,
          ),
          Expanded(
              child: EasyRefresh(
                  controller: state.easyRefreshController,
                  header: MaterialHeader(
                      completeDuration: Duration(milliseconds: 0)),
                  footer: MaterialFooter(),
                  firstRefresh: true,
                  enableControlFinishRefresh: true,
                  enableControlFinishLoad: true,
                  onRefresh: () async {
                    //下拉刷新
                    state..page = 1;
                    dispatch(homeWorkListActionCreator.onRefresh());
                  },
                  onLoad: () async {
                    //上拉加载
                    state..page = state.page + 1;
                    dispatch(homeWorkListActionCreator.onload());
                  },
                  child: _list(state, dispatch, viewService))),

        ],
      ),
    ),context: viewService.context

  );
}
Widget _list(
    homeWorkListState state, Dispatch dispatch, ViewService viewService) {
  if(state.item.isNotEmpty){
    return ListView.builder(
        padding: EdgeInsets.zero,
        itemBuilder: (BuildContext contentext, int index){
          return Container(
            padding: EdgeInsets.only(top: 10, bottom: 10, left: 15, right: 15),
            margin: EdgeInsets.only(top: 5, bottom: 5, left: 15, right: 15),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.elliptical(10, 10)),
              color: Colors.white,
            ),
            child:Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                    state.item[index].createTime,
                  textAlign: TextAlign.start,
                  style: TextStyle(
                      color: AppColors.smallTextColor,
                      fontSize: 12,
                      ),
                ),
                Container(
                  margin: EdgeInsets.only(top: 10),

                  child:Text(
                    state.item[index].taskContent,
                    textAlign: TextAlign.start,
                    style: TextStyle(
                        color: AppColors.middleTextColor,
                        fontSize: 15,
                    ),
                  ) ,
                ),

              ],
            ) ,
          );

        },itemCount: state.item.length,

    );
  }else {
    return noMemberWidget();
  }

}